/*
 * Created on 2004-01-06
 */
package org.opencube.oms.util;

import java.util.Collection;
import java.util.Iterator;

import org.opencube.oms.OMSNode;

/**
 * Provides some utility methods.
 *  
 * @author <a href="mailto:maciek@fingo.pl">FINGO - Maciej Mroczko</a>
 */
public class OMSUtil
{
	/**
	 * Return first <code>OMSNode</code> from the given list with the specified id.
	 *  
	 * @param nodeList - the list of nodes to search
	 * @param id - the id of the node to find
	 * 
	 * @return OMSNode - the node with the given id, null if not found  
	 */
	public static OMSNode getNodeById( Collection nodeList, String id )
	{
		if( nodeList != null )
		{
			Iterator it = nodeList.iterator();
			while( it.hasNext() )
			{
				OMSNode node = ( OMSNode ) it.next(); 
				if( node.getId().equals( id ) )
				{
					return node; 
				}
			}
		}
		return null;
	}
	
	/**
	 * Return first <code>OMSNode</code> from the given list with the specified name.
	 *  
	 * @param nodeList - the list of nodes to search
	 * @param name - the name of the node to find
	 * 
	 * @return OMSNode - the node with the given name, null if not found
	 */
	public static OMSNode getNodeByName( Collection nodeList, String name )
	{
		if( nodeList != null )
		{
			Iterator it = nodeList.iterator();
			while( it.hasNext() )
			{
				OMSNode node = ( OMSNode ) it.next(); 
				if( node.getName().equals( name ) )
				{
					return node; 
				}
			}
		}
		return null;
	}
	
}
